package com.ruoyi.email.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.RedisUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.VerCodeGenerateUtil;
import com.ruoyi.email.domain.Email;
import com.ruoyi.email.service.IEmailService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

/**
 * @version IntelliJ IDEA || java version 11.
 * @Author: Oliver
 * @Description: 邮箱验证码
 * @Date: 2023-07-02
 * @Time: 15:06
 */
@RestController
@RequestMapping("/email")
public class EmailController {

    @Autowired
    private IEmailService mailService;


    /**
    * @Description: 发送邮箱验证码
    * @Param: [email]
    * @return: com.ruoyi.common.core.domain.AjaxResult
    * @Author: xgw
    * @Date: 2025/1/10
    */
    @PostMapping ("/sendEmail")
    public AjaxResult sendEmail(@RequestBody Email email) {
        //判断参数是否正确
        if(email == null || email.getTos() == null ) {
            return AjaxResult.error(500, "参数错误!");
        }
       return mailService.sendEmail(email);
    }

    @GetMapping("/verityEmailCode")
    public AjaxResult verityEmailCode(@RequestParam("emailCode") String emailCode,@RequestParam("tos") String tos){
        //判断参数是否正确
        if(emailCode == null || tos == null ) {
            return AjaxResult.error(500, "参数错误，不能为null!");
        }
       return mailService.verityEmailCode(emailCode,tos);
    }
}
